package model.util;

public class Vector3D {

    /** Attributs */
    private double m_x, m_y, m_z;

    /** Constructeurs */
    public Vector3D(double x, double y)
    { this(x, y, 0.0); }

    public Vector3D(Vector3D other) 
    { this(other.m_x,other.m_y,other.m_z); }

    public Vector3D(double x, double y, double z) {
        m_x = x;
        m_y = y;
        m_z = z;
    }

    /** Accesseurs */
    public double getX() { return m_x; }
    public double getY() { return m_y; }
    public double getZ() { return m_z; }

    /** Mutateurs */
    public void setX(double x) { m_x = x; }
    public void setY(double y) { m_y = y; }
    public void setZ(double z) { m_z = z; }

    /** Predicats */
    public boolean equals(Vector3D vector) 
    { return m_x == vector.m_x && m_y == vector.m_y && m_z == vector.m_z; }

    public boolean lowerThan(Vector3D vector) 
    { return m_x < vector.m_x && m_y < vector.m_y && m_z < vector.m_z; }

    public boolean greaterThan(Vector3D vector) 
    { return m_x > vector.m_x && m_y > vector.m_y && m_z > vector.m_z; }

    /** Methodes */
    public void affect(Vector3D source) {
        m_x = source.m_x;
        m_y = source.m_y;
        m_z = source.m_z;
    }

    public Vector3D abs() 
    { return new Vector3D(Math.abs(m_x), Math.abs(m_y), Math.abs(m_z)); }

    public Vector3D add(Vector3D target) 
    { return new Vector3D(m_x + target.m_x, m_y + target.m_y, m_z + target.m_z); }

    public Vector3D sub(Vector3D target) 
    { return new Vector3D(m_x - target.m_x, m_y - target.m_y, m_z - target.m_z); }

    public Vector3D times(double factor) 
    { return new Vector3D(m_x * factor, m_y * factor, m_z * factor); } 

    public Vector3D divide(double quotient) 
    { return new Vector3D(m_x / quotient, m_y / quotient, m_z / quotient); } 

    public Vector3D median(Vector3D target) 
    { return add(target).divide(2.0); }

    public double squareDistance(Vector3D target) {
        double dx = target.m_x - m_x;
        double dy = target.m_y - m_y;
        double dz = target.m_z - m_z;
        return (dx*dx + dy*dy + dz*dz);
    }

    public double distance(Vector3D target) 
    { return java.lang.Math.sqrt(squareDistance(target)); }

    public String toString() 
    { return "Vector3D(" + m_x + ", " + m_y + ", " + m_z + ")"; }
}